import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  // {
  //   path: "/two",
  //   name: "two",
  //   component: () => import("../views/TwoWord/index.vue"),
  //   meta: {
  //     title: "Two",
  //     isshow: true,
  //   },
  // },

  {
    path: "/",
    name: "login",
    component: () => import("../views/LoginView/loginView.vue"),
    meta: {
      title: "登录",
    },
  },
  {
    path: "/all",
    name: "all",
    component: () => import("../views/AllView/AllView.vue"),
    meta: {
      title: "全部",
      isshow: true,
    },
    children: [
      {
        path: "/table",
        name: "table",
        component: () => import("../views/AllView/TableView/tableView.vue"),
        meta: {
          title: "table",
          isshow: true,
        },
      },
      {
        path: "/three",
        name: "three",
        component: () => import("../views/AllView/ThreeWord/Three.vue"),
        meta: {
          title: "Three",
          isshow: true,
        },
      },
      {
        path: "/timepack",
        name: "timepack",
        component: () => import("../views/AllView/timePack/index.vue"),
        meta: {
          title: "timepack",
          isshow: true,
        },
      },
      {
        path: "/Carousel",
        name: "Carousel",
        component: () => import("../views/AllView/Carousel/index.vue"),
        meta: {
          title: "走马灯",
          isshow: true,
        },
      },
      {
        path: "/tree",
        name: "tree",
        component: () => import("../views/AllView/tree/index.vue"),
        meta: {
          title: "树形组件",
          isshow: true,
        },
      },
      {
        path: "/ajax",
        name: "ajax",
        component: () => import("../views/AllView/ajax/index.vue"),
        meta: {
          title: "Promise封装ajax",
          isshow: true,
        },
      },
      {
        path: "/ImageVerification",
        name: "ImageVerification",
        component: () => import("../views/AllView/ImageVerification/index.vue"),
        meta: {
          title: "图片验证",
          isshow: true,
        },
      },
      {
        path: "/media",
        name: "media",
        component: () => import("../views/AllView/mediaQuery"),
        meta: {
          title: "媒体查询",
          isshow: true,
        },
      },
      {
        path: "/mora",
        name: "mora",
        component: () => import("../views/AllView/Mora"),
        meta: {
          title: "猜拳游戏",
          isshow: true,
        },
      }
      ,
      {
        path: "/vuedraggable",
        name: "vuedraggable",
        component: () => import("../views/AllView/vuedraggable"),
        meta: {
          title: "拖拽组件",
          isshow: true,
        },
      }
      ,
      {
        path: "/luckydraw",
        name: "luckydraw",
        component: () => import("../views/AllView/luckyDraw"),
        meta: {
          title: "幸运抽奖",
          isshow: true,
        },
      }
     
      ,
      {
        path: "/watermark",
        name: "watermark",
        component: () => import("../views/AllView/watermark"),
        meta: {
          title: "水印",
          isshow: true,
        },
      }
      ,
      {
        path: "/loadText",
        name: "loadText",
        component: () => import("../views/AllView/loadText"),
        meta: {
          title: "加载文字",
          isshow: true,
        },
      }
    ],

  },
  {
    path: "*",
    name: 404,
    component: () => import("../views/Error404"),
    meta: {
      title: "404",
    },
  },
];

const router = new VueRouter({
  routes,
  // mode:'history'
});
router.beforeEach((to, from, next) => {
  if (to.meta.isshow) {
    if (localStorage.getItem("token")) {
      next();
    } else {
      next({ name: "login" });
    }
  } else {
    next();
  }
});
router.afterEach((to, next) => {
  document.title = to.meta.title;
});
export default router;
